<?php
$this->LoadHelper('ApiHelper');
$ApiHelper = new ApiHelper();

switch ($this->Param['option']) {
    case 'sendsms':
        $mobile = empty($this->Param['mobile']) ? ErrorMsg::ApiMsg('请填写手机号') : $this->Param['mobile'];
        if(!Validator::isMobile($mobile)){
            ErrorMsg::ApiMsg('手机号错误');
        }
        $this->LoadHelper('MemberHelper');
        $MemberHelper = new MemberHelper();
        $member_info = $MemberHelper->getMemberRow(array('`u_status` = ?' => 'ok', '`u_mobile` = ?' => $mobile));      
        if(empty($member_info)){
            ErrorMsg::ApiMsg('不存在当前用户');
        }
        
        $this->LoadHelper('SmsHelper');
        $SmsHelper = new SmsHelper();
        $this->LoadResurces('sms/class.sms');
        $sms = new Sms();
        $rnd = StringCode::RandomCode(4, 'num');
        $do = $sms->sendsms($mobile, '您的验证码是：'.$rnd);
        if($do == '0'){
            $SmsHelper->verifySave(array(
                'sms_mobile' => $mobile,
                'sms_code' => $rnd,
                'sms_dateline' => NOW_TIME,
                'sms_ip' => C_IP
            ));
            $ApiHelper->logSave('sendsms', $this->Param);
            ErrorMsg::ApiMsg('发送成功', 0);
        }else{
            ErrorMsg::ApiMsg('发送失败');
        }
        
        break;
    case 'province':
        $this->LoadHelper('CityHelper');
        $CityHelper = new CityHelper();
        $data = $CityHelper->provinceAll();
        $ApiHelper->logSave('getprovince', $this->Param);
        ErrorMsg::ApiMsg('获取成功', 0, $data);
    case 'city':
        $province = empty($this->Param['province']) ? ErrorMsg::ApiMsg('请传入省份名称') : $this->Param['province'];
        $this->LoadHelper('CityHelper');
        $CityHelper = new CityHelper();
        $data = $CityHelper->cityAll($province,$this->Param['bank_id']);
        $ApiHelper->logSave('getcity', $this->Param);
        ErrorMsg::ApiMsg('获取成功', 0, $data);
        break;
    case 'area':
        //$province = empty($this->Param['province']) ? ErrorMsg::ApiMsg('请传入省份名称') : $this->Param['province'];
        $city = empty($this->Param['city']) ? ErrorMsg::ApiMsg('请传入市名称') : $this->Param['city'];
        $this->LoadHelper('CityHelper');
        $CityHelper = new CityHelper();
        $data = $CityHelper->getArea($city,$this->Param['bank_id']);
        $ApiHelper->logSave('getarea', $this->Param);
        ErrorMsg::ApiMsg('获取成功', 0, $data);
        break;
    case 'dictionary':
        $type = empty($this->Param['type']) ? '学历' : $this->Param['type'];
        if($type == '产品类型'){
            $bk_id = empty($this->Param['bank_id']) ? ErrorMsg::ApiMsg('银行值错误') : $this->Param['bank_id'];
            $ot_loan_year = empty($this->Param['ot_loan_year']) ? ErrorMsg::ApiMsg('贷款年限值错误') : $this->Param['ot_loan_year'];
            $this->LoadHelper('BankHelper');
            $BankHelper = new BankHelper();
            $rt_all = $BankHelper->rateAll(array('`rt_status` = ?' => 'ok', '`rt_bank_id` = ?' => $bk_id, '`rt_ylimit` = ?' => $ot_loan_year), array('rt_type'), array('rt_type'));
            $arr = array();
            if(!empty($rt_all)) foreach($rt_all as $k => $v){
                $arr[] = array(
                   'd_id' => $v['rt_id'],
                   'd_fid' => 0,
                   'd_text' => $v['rt_type']
                );
                $data = $arr;
            }
        }else{
            $url = 'http://dictapi.app.qiche100.com/public/index/option/dict?type=' . $type;
            $data = file_get_contents($url);
            $data = json_decode($data, TRUE);
        }
        $ApiHelper->logSave('getdictionary', $this->Param);
        ErrorMsg::ApiMsg('获取成功', 0, $data);
        break;
    default;
}